﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Autodesk.AutoCAD.Geometry;
using Autodesk.AutoCAD.DatabaseServices;
using Autodesk.AutoCAD.EditorInput;
using Autodesk.AutoCAD.ApplicationServices;
using Galaxy.AutoCAD.Databases;

namespace Galaxy.AutoCAD.Editors
{
    public static class LineJigTool
    {
        public static Extents3d GetLineJigExtens3d()
        {
            Extents3d result = new Extents3d(Point3d.Origin, Point3d.Origin);
            Document doc = Application.DocumentManager.MdiActiveDocument;
            Editor ed = doc.Editor;
            Database db = doc.Database;
            ObjectId objectId = ObjectId.Null;
            LineJig lj = new LineJig();
            PromptResult pr = ed.Drag(lj);
            if (pr.Status == PromptStatus.OK)
            {
                lj.SetCounter(1);
                pr = ed.Drag(lj);
                objectId = db.AddToModelSpace(lj.Entity);
            }
            DBObjectCollection dBObjCol = SelectionTool.SelectLastCreateDBObject();
            if (dBObjCol.Count == 1)
            {
                if (dBObjCol[0] is Line)
                {
                    Line line = (Line)dBObjCol[0];
                    result = line.Bounds.Value;
                    line.ObjectId.Remove();
                }
            }
            return result;
        }
    }
}
